package com.aounhui.queue.controller;

import com.aounhui.common.entity.Message;
import com.aounhui.common.entity.Result;
import com.aounhui.queue.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author aounhui
 * @version 1.0
 * @date 2021/6/30 10:44
 * @description
 */
@RestController
@Slf4j
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping(value = "/queue/message/post")
    public Result sendMessage(@RequestBody Message message) {
        try {
            messageService.sendMessage(message.getType(), message.getContent());
            return Result.ok();
        } catch (Exception e) {
            log.error("queue服务发送消息失败");
            e.printStackTrace();
            return Result.error("消息发送失败");
        }
    }
}
